/*
** xfunc.c for zappy in /home/fassi_c//zappy2/zappouet/server/utils
**
** Made by clement fassi
** Login   <fassi_c@epitech.net>
**
** Started on  Wed Jun 29 12:01:55 2011 clement fassi
** Last update Wed Jun 29 12:01:57 2011 clement fassi
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void	*xmalloc(size_t size)
{
  void	*ptr;

  if ((ptr = malloc(size)))
    return (ptr);
  fputs("Error: can't allocate memory.\n", stderr);
  exit(EXIT_FAILURE);
}

ssize_t	xwrite(int fd, const void *buf, size_t count)
{
  ssize_t	nb;

  if ((nb = write(fd, buf, count)) == -1)
    {
      fputs("Error: can't write.\n", stderr);
      exit(EXIT_FAILURE);
    }
  return (nb);
}

ssize_t xread(int fd, void *buf, size_t count)
{
  ssize_t	nb;

  if ((nb = read(fd, buf, count)) == -1)
    {
      fputs("Error: can't read.\n", stderr);
      exit(EXIT_FAILURE);
    }
  return (nb);
}
